import React, { useRef, useState, useEffect, createRef } from 'react';

// useRef保存的是同一个引用，createRef是最新的引用
export default () => {
    const [count, setCount] = useState(0);
    const preRef = useRef(0);
    useEffect(() => {
        // console.log('useEffect come');
        preRef.current += 1;
    });
    return (
        <div>
            <p onClick={() => {
                setTimeout(() => {
                    console.log('preRef.current:', preRef.current);
                }, 2000);
            }}>precount: {preRef.current}</p>
            <p>you clicked: {count}</p>
            <button onClick={() => { setCount(count + 1); preRef.current + 1; }}>click me</button>
        </div>
    );
};